package com.shen;

import java.io.File;
import java.lang.reflect.Field;
import java.util.Scanner;

/**
 * Author:shen
 * CreateDate:2020/6/3.
 * Function:
 */
public class demo02 {
    static Scanner scanner=new Scanner(System.in);
    public static void main(String[] args) {
        System.out.println("请输入一个文件夹名：");
        String dirName=scanner.nextLine();
        File file=new File(dirName);
        if(file.exists()){
            printDirFiles(file);
        }else{
            System.out.println("该文件不存在！");
        }

    }

    public static void printDirFiles(File file){
        if(file.isDirectory()){
            File[] files = file.listFiles();
            getFile(files);
        }else{
            System.out.println("该文件不是一个文件夹！");
        }
    }
    public static void getFile(File[] files){
        for (File sonFile:files) {
            if(sonFile.isDirectory()){
                System.out.println("dir:"+sonFile.getName()+" size:"+sonFile.length());
              getFile(sonFile.listFiles());
            }
            if(sonFile.isFile()){
                System.out.println("file:"+sonFile.getName());
            }
        }
    }
}
